package com.example.service.impl;

import com.example.mapper.StuMapper;
import com.example.pojo.Clazz;
import com.example.pojo.PageResult;
import com.example.pojo.StuQueryParam;
import com.example.pojo.Student;
import com.example.service.StuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StuServiceimpl implements StuService {

    @Autowired
    private StuMapper stuMapper;

    @Override
    public PageResult<Student> list(StuQueryParam stuQueryParam) {
        PageHelper.startPage(stuQueryParam.getPage(), stuQueryParam.getPageSize());

        List<Student> studentList = stuMapper.list(stuQueryParam);

        Page<Student> p = (Page<Student>) studentList;

        return new PageResult<Student>(p.getTotal(), studentList);

    }

    @Override
    public void delete(List<Integer> ids) {
        stuMapper.delete(ids);
    }

    @Override
    public void insert(Student stu) {
        stu.setCreateTime(LocalDateTime.now());
        stu.setUpdateTime(LocalDateTime.now());
        stuMapper.insert(stu);
    }

    @Override
    public Student selectByID(Integer id) {
        return stuMapper.selectByID(id);
    }

    @Override
    public void updata(Student stu) {
        stu.setUpdateTime(LocalDateTime.now());
        stuMapper.updata(stu);

    }

    @Override
    public void DisciplinaryDisposition(Integer id, Integer score) {
        stuMapper.DisciplinaryDisposition(id, score);
    }
}
